/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package experiments;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author minaev
 */
public class DBInputStream extends InputStream {

        InputStream is;
        Connection con;
        Statement s;
        String sql_sel = "SELECT `ser_obj` FROM `ser_exp_data` "
                + "WHERE `num_exp`=1;";
                

        public DBInputStream() throws ClassNotFoundException, SQLException, IOException {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
                    "root", "root");
            s = con.createStatement();
            ResultSet rs = s.executeQuery(sql_sel);
            rs.next();
            is = rs.getBlob("ser_obj").getBinaryStream();
            int bf;
            while((bf = is.read())!=-1){
                System.out.println("blob:is:"+Integer.toHexString(bf));
            }
        }
        
        int b;
        @Override
        public int read() throws IOException {
            b = is.read();
            System.out.println("i: "+Integer.toHexString(b));
            return b;
        }
    }
